package org.liveboardgames.agricola.business.action.processor;

import java.util.List;

import org.liveboardgames.agricola.business.updater.CardUpdater;
import org.liveboardgames.agricola.business.updater.PlayerUpdater;
import org.liveboardgames.agricola.domain.Change;
import org.liveboardgames.agricola.domain.Game;
import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.card.Card;
import org.liveboardgames.agricola.domain.common.Peep;
import org.liveboardgames.agricola.domain.player.Player;
import org.liveboardgames.agricola.model.enums.BirthStatusEnum;

public class BirthActionProcessor extends ActionProcessor {

  public BirthActionProcessor(Game game, Action action, List<Change> changes) {
    super(game, action, changes);
  }

  @Override
  public void execute() {
    Player player = (Player)action.getTarget();

    // Create a new peep
    Peep peep = new Peep();
    peep.setStatus(BirthStatusEnum.NEWBORN);
    new PlayerUpdater(player, changes).addPeep(peep);

    // The card that holds the peeps
    if (action.getLink() != null && action.getLink() instanceof Card) {
      Card card = (Card)action.getLink();
      new CardUpdater(card, changes).addPeep(peep);
    }
  }

}
